#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<vector>
using namespace std;

struct TreeNode {
	int val;
	TreeNode *left;
	TreeNode *right;
	TreeNode() : val(0), left(nullptr), right(nullptr) {}
	TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
	TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
};

TreeNode* ComTree(TreeNode* t1, TreeNode* t2)
{
	if (t1 == nullptr)
		return t2;
	if (t2 == nullptr)
		return t1;
	t1->val = t1->val + t2->val;
	t1->left = ComTree(t1->left, t2->left);
	t2->right = ComTree(t1->right, t2->right);
}
TreeNode* mergeTrees(TreeNode* root1, TreeNode* root2) {
	return ComTree(root1, root2);
}

TreeNode*ResVal(TreeNode* root, int val)
{
	if (root == nullptr || root->val == val)
	{
		return root;
	}
	TreeNode* cur = nullptr;
	if (root != nullptr&&root->val>val)
	{
		cur = ResVal(root->left, val);
	}
	if (root != nullptr&&root->val<val)
	{
		cur = ResVal(root->right, val);
	}
	return cur;
}
TreeNode* searchBST(TreeNode* root, int val) {
	return ResVal(root, val);
}